#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2024/1/23 17:11
# @Author : 闫峰
# @File    : test_monitor_handler_failure.py
from utils.get_all_mongodb_data import GetAllMongodbData
from utils.logging_tool.init_logger import init_logger
from utils.mysqlUtils.mongodb_utils import MongoDBLink
from utils.noticeUtils.dingtalkControl import DingTalkSendMsg

INFO, ERROR, WARNING = init_logger()


class MHF:

    def monitor_handler_failure(self):
        coll_name_list = ["Aliexpress_Listing_Sensitive", "Allegro_Listing_Sensitive",
                              "JDWalmart_Listing_Sensitive", "Kogan_Listing_Sensitive", "Lazada_Listing_Sensitive",
                              "Shopee_Listing_Sensitive", "Walmart_Listing_Sensitive"]
        text = ""
        for coll_name in coll_name_list:
            uri = "mongodb://reader:33oQm3o6nA9HaLhW#@139.159.193.165:8635,121.37.18.161:8635/?authSource=admin"
            dbname = "zhcxkj_riskworker"
            coll_name = coll_name
            filter_sql = {"AuditStatus": 1,"DealStatus":3}
            # projection = {"DealUniqueId": 1, "_id": 1, "OrderSourceId": 1, "ProductId": 1}
            md = MongoDBLink( uri=uri,dbname=dbname,coll_name=coll_name)
            res = md.count(filter_sql)
            text += f"{coll_name}->侵权词同步失败数：<font color='red' size='5'>{res}</font>   \n" \
                    f"---  \n\n"
        # 发送钉钉告警
        DingTalkSendMsg(DingTalk='infringement_monitor').send_success(text=text,
                                                                 title='侵权词监控服务(测试组)',
                                                                 phone_list=[18118758151,13242975788,13760465541])


if __name__ == '__main__':
    MHF().monitor_handler_failure()